package com.qf.service.Impl;/*
    Dell
    2021/10/2
    11:16
*/

import com.qf.dao.HealthDao;
import com.qf.dao.Impl.HealthDaoImpl;
import com.qf.entiy.Health;
import com.qf.service.HealthService;
import com.qf.util.DruidUtil;
import com.qf.util.Page;

import java.util.List;

public class HealthServiceImpl implements HealthService {
    private HealthDao healthDao  = new HealthDaoImpl();
    @Override
    public List<Health> showAllHealth(Page page) {
        List<Health> healthList = null;
        Long aLong = healthDao.countHealth();
        page.setTotalCount(aLong);
        healthList =  healthDao.showAllHealth(page);
        DruidUtil.close();
        return healthList;
    }

    @Override
    public Integer addHealth(Health health, Integer organId) {
        int result = 0;
        try {
            DruidUtil.begin();
            result = healthDao.insertHealth(health, organId);
            DruidUtil.commit();
        } catch (Exception e) {
            e.printStackTrace();
            DruidUtil.rollback();
        } finally {
            DruidUtil.close();
        }
        return result;
    }

    @Override
    public Integer updateHealth(Health health, Integer organId) {
        int result = 0;
        try {
            DruidUtil.begin();
            result = healthDao.updateHealth(health, organId);
            DruidUtil.commit();
        } catch (Exception e) {
            e.printStackTrace();
            DruidUtil.rollback();
        } finally {
            DruidUtil.close();
        }
        return result;
    }

    @Override
    public Integer deleteHealth(Integer organId) {
        int result = 0;
        try {
            DruidUtil.begin();
            result = healthDao.deleteHealth(organId);
            DruidUtil.commit();
        } catch (Exception e) {
            e.printStackTrace();
            DruidUtil.rollback();
        } finally {
            DruidUtil.close();
        }
        return result;
    }
}
